package com.ltmall.api.manager.impl;

import com.ltmall.api.bean.AreaPostage;
import com.ltmall.api.bean.LogisticPattern;
import com.ltmall.api.bean.LogisticPatternExc;
import com.ltmall.api.bean.OrderLogistic;
import com.ltmall.api.dao.impl.LogisticDAO;
import com.ltmall.api.manager.LogisticManager;

import java.util.List;

public class LogisticManagerImpl implements LogisticManager {
	private LogisticDAO lDAO;
	
	public LogisticDAO getlDAO() {
		return lDAO;
	}

	public void setlDAO(LogisticDAO lDAO) {
		this.lDAO = lDAO;
	}

	public List<LogisticPatternExc> getPatternExc(int patternID) {
		// TODO Auto-generated method stub
		return lDAO.getPatternExc(patternID);
	}

	public LogisticPattern getPattern(int patternID) {
		// TODO Auto-generated method stub
		return lDAO.getPattern(patternID);
	}

	public boolean addOrderLogistic(OrderLogistic oLogistic) {
		// TODO Auto-generated method stub
		return lDAO.addOrderLogistic(oLogistic);
	}

	public LogisticPatternExc getPatternExc(int patternID, String address,
			int type) {
		// TODO Auto-generated method stub
		return lDAO.getPatternExc(patternID, address, type);
	}

	public boolean setOrderID(int orderID, int logisticID) {
		// TODO Auto-generated method stub
		return lDAO.setOrderID(orderID, logisticID);
	}

	public LogisticPatternExc getPatternExc(int patternID, String province,
			String city) {
		// TODO Auto-generated method stub
		/*
		 * 先看看带市的有没有，再看看不带市的有没有
		 */
		
		LogisticPatternExc exc=null;
		
		if(city!=null){
			exc = lDAO.getPatternExc(patternID, province, city);
			if(exc==null){
				exc = lDAO.getPatternExcNoCity(patternID, province);
			}
		}else{
			exc = lDAO.getPatternExcNoCity(patternID, province);
		}
		return exc;
//		return lDAO.getPatternExc(patternID, province, city);
	}

	public int logiType(int goodsID) {
		// TODO Auto-generated method stub
		return lDAO.logiType(goodsID);
	}

	public AreaPostage getPostage(int patternID, String province,String city) {
		// TODO Auto-generated method stub
		AreaPostage ap =null;
		ap = lDAO.getPostage(patternID, city,1);//看看有没有市
		if(ap == null){
			ap =lDAO.getPostage(patternID, province,2);//看看有没有省
		}
		return ap;
	}

	public AreaPostage getNoPostage(int patternID, String province,
			String city) {
		// TODO Auto-generated method stub
		AreaPostage ap = lDAO.getNoPostage(patternID, city, 1);
		if (ap == null) {
			ap = lDAO.getNoPostage(patternID, province, 2);
		}
		if (ap == null) {
			ap = lDAO.getNoPostage(patternID, province, 0);
		}
		return ap;
	}

	public AreaPostage getNationPostage(int patternID) {
		// TODO Auto-generated method stub
		return lDAO.getNationPostage(patternID);
	}

}
